{ "name": "Vector Math", "script": "VecMath.js", "version": "1.0", "previousversions": [], "description": "# Vector Math\r\rThis script provides a small library of vector mathematics operations used by\rother scripts to assist in geometric computations. For example, this is\rused prominently in the ```Token Collisions``` script.\r\r## API Documentation\r\rThe following functions are exposed by the ```VecMath``` object:\r\r```\r**\r * Adds two vectors.\r * @param {vec} a\r * @param {vec} b\r * @return {vec}\r */\rfunction add(a, b)\r```\r\r```\r/**\r * Creates a cloned copy of a vector.\r * @param {vec} v\r * @return {vec}\r */\rfunction clone(v)\r```\r\r```\r/**\r * Returns the cross product of two 3D vectors.\r * @param {vec3} a\r * @param {vec3} b\r * @return {vec3}\r */\rfunction cross(a, b)\r```\r\r```\r/**\r * Returns the degree of a vector - the number of dimensions it has.\r * @param {vec} vector\r * @return {int}\r */\rfunction degree(vector)\r```\r\r```\r/**\r * Computes the distance between two points.\r * @param {vec} pt1\r * @param {vec} pt2\r * @return {number}\r */\rfunction dist(pt1, pt2)\r```\r\r```\r/**\r * Returns the dot product of two vectors.\r * @param {vec} a\r * @param {vec} b\r * @return {number}\r */\rfunction dot(a, b)\r```\r\r```\r/**\r * Tests if two vectors are equal.\r * @param {vec} a\r * @param {vec} b\r * @param {float} [tolerance=0] A tolerance threshold for comparing vector\r * components. \r * @return {boolean} true iff the each of the vectors' corresponding\r * components are equal.\r */\rfunction equal(a, b, tolerance)\r```\r\r```\r/**\r * Returns the length of a vector.\r * @param {vec} vector\r * @return {number}\r */\rfunction length(vector)\r```\r\r```\r/**\r * Computes the normalization of a vector - its unit vector.\r * @param {vec} v\r * @return {vec}\r */\rfunction normalize(v)\r```\r\r```\r/**\r * Computes the projection of vector b onto vector a.\r * @param {vec} a\r * @param {vec} b\r * @return {vec}\r */\rfunction projection(a, b)\r```\r\r```\r/**\r * Computes the distance from a point to an infinitely stretching line.\r * Works for either 2D or 3D points.\r * @param {vec2 || vec3} pt\r * @param {vec2 || vec3} linePt1 A point on the line.\r * @param {vec2 || vec3} linePt2 Another point on the line.\r * @return {number}\r */\rfunction ptLineDist(pt, linePt1, linePt2)\r```\r\r```\r/**\r * Computes the distance from a point to a line segment.\r * Works for either 2D or 3D points.\r * @param {vec2 || vec3} pt\r * @param {vec2 || vec3} linePt1 The start point of the segment.\r * @param {vec2 || vec3} linePt2 The end point of the segment.\r * @return {number}\r */\rfunction ptSegDist(pt, linePt1, linePt2)\r```\r\r```\r/**\r * Computes the scalar projection of b onto a.\r * @param {vec2} a\r * @param {vec2} b\r * @return {vec2}\r */\rfunction scalarProjection(a, b)\r```\r\r```\r/**\r * Computes a scaled vector.\r * @param {vec2} v\r * @param {number} scalar\r * @return {vec2}\r */\rfunction scale(v, scalar)\r```\r\r```\r/**\r * Computes the difference of two vectors.\r * @param {vec} a\r * @param {vec} b\r * @return {vec}\r */\rfunction sub(a, b)\r```\r\r```\r/**\r * Returns the vector from pt1 to pt2.\r * @param {vec} pt1\r * @param {vec} pt2\r * @return {vec}\r */\rfunction vec(pt1, pt2)\r```\r", "authors": "Stephen Lindberg", "roll20userid": 46544, "useroptions": [], "dependencies": {}, "modifies": {}, "conflicts": [] }